<?php

						/*************************************\
						
						    Handshakes Professional (4.1)
						            by DZOIC LLC
						       Copyright(c) 2005-2011
						        http://www.dzoic.com
						
						\*************************************/

function hs_mail($var1,$var2,$var3 = null,$var4 = null,$var5 = null){
	
	if(!$var5)
		return @mail($var1,$var2,$var3,$var4);
	else
		return @mail($var1,$var2,$var3,$var4,$var5);
	
}//hs_mail

function hs_mail_header($var,$encoding){
	
	$var = "=?".$encoding."?B?".base64_encode($var)."?=";
	return $var;
	
}//hs_mail_header

function hs_strlen($var){
	
	if(function_exists("mb_strlen"))
		return mb_strlen($var,extract_encoding("html"));
	else
		return strlen($var);
	
}//hs_strlen

function hs_strpos($var1,$var2,$var3 = null){
	
	if(function_exists("mb_strpos"))
		return mb_strpos($var1,$var2,$var3,extract_encoding("html"));
	else
		return strpos($var1,$var2,$var3);
	
}//hs_strpos

function hs_strrpos($var1,$var2){
	
	if(function_exists("mb_strrpos"))
		return mb_strrpos($var1,$var2,extract_encoding("html"));
	else
		return strrpos($var1,$var2);
	
}//hs_strrpos

function hs_substr($var1,$var2,$var3 = null){
	
	if(function_exists("mb_substr"))
		return mb_substr($var1,$var2,$var3,extract_encoding("html"));
	else
		return substr($var1,$var2,$var3);
	
}//hs_substr

function hs_strtolower($var){
	
	if(function_exists("mb_strtolower"))
		return mb_strtolower($var,extract_encoding("html"));
	else
		return strtolower($var);
	
}//hs_strtolower

function hs_strtoupper($var){
	
	if(function_exists("mb_strtoupper"))
		return mb_strtoupper($var,extract_encoding("html"));
	else
		return strtoupper($var);
	
}//hs_strtoupper

function hs_substr_count($var1,$var2){
	
	if(function_exists("mb_substr_count"))
		return mb_substr_count($var1,$var2,extract_encoding("html"));
	else
		return substr_count($var1,$var2);
	
}//hs_substr_count

function hs_ereg($var1,$var2,$var3 = null){
	
	if(function_exists("mb_ereg"))
		return mb_ereg($var1,$var2,$var3);
	else
		return preg_match('/'.$var1.'/',$var2,$var3);
	
}//hs_ereg

function hs_ereg_replace($var1,$var2,$var3){
	
	if(function_exists("mb_ereg_replace"))
		return mb_ereg_replace($var1,$var2,$var3);
	else
		return preg_replace('/'.$var1.'/',$var2,$var3);
	
}//hs_ereg_replace

function hs_eregi($var1,$var2,$var3 = null){
	
	if(function_exists("mb_eregi"))
		return mb_eregi($var1,$var2,$var3);
	else
		return preg_match('/'.$var1.'/i',$var2,$var3);
	
}//hs_eregi

function hs_eregi_replace($var1,$var2,$var3){
	
	if(function_exists("mb_eregi_replace"))
		return mb_eregi_replace($var1,$var2,$var3);
	else
		return preg_replace('/'.$var1.'/i',$var2,$var3);
	
}//hs_eregi_replace

function hs_split($var1,$var2,$var3 = null){
	
	if(function_exists("mb_split"))
		return mb_split($var1,$var2,$var3);
	else
		return split($var1,$var2,$var3);
	
}//hs_split

function hs_convert_encoding($var1,$var2,$var3){
	
	if(function_exists("mb_convert_encoding"))
		return mb_convert_encoding($var1,$var2,$var3);
	else
		return $var1;
	
}//hs_convert_encoding

function hs_parse_str($var1){
	
	if(function_exists("mb_parse_str"))
		mb_parse_str($var1,$var2);	
	else
		parse_str($var1,$var2);
	
	return $var2;
	
}//hs_parse_str

function hs_wordwrap($txt, $limit=10, $divider="&#8203;", $parse_links = 1){
	
	preg_match_all('/((http|https|ftp):\/\/|www)[a-z0-9\-\._]+\/?[a-z0-9_\.\-\?\+\/~=&#;,]*[a-z0-9\/]{1}/si',$txt,$links);
	$links = array_unique($links[0]);
	
	foreach( $links as $k => $lnk ) {
		$txt = preg_replace( "/".preg_quote( $lnk, "/" )."/", "[dzLink][".$k."]", $txt );
	}
	
	preg_match_all( "/[^\!|\%|\(|\)|-|\}|\{|\]|\[|\?|,|\.|\n| ]+/", $txt, $words );	
	foreach($words[0] as $word){
		if(hs_strlen($word) > $limit){
			$parts = array();
			$number_of_parts = hs_strlen($word)+($limit-(hs_strlen($word)%$limit));
			for($i=0;$i<=$number_of_parts;$i=$i+$limit){
				$parts[] = hs_substr($word,$i,$limit);
			}//for
			$parts = handle_empties($parts);
			$newword = implode($divider,$parts);
			$txt = hs_ereg_replace(preg_quote($word),$newword,$txt);
		}
	}//foreach
	
	preg_match_all( "/\[dzLink\]\[([0-9]+)\]/", $txt, $links_replaced );
	foreach( $links_replaced[0] as $k => $code ) {
		$key = $links_replaced[1][$k];
		if($parse_links){
			if(substr($links[$key],0,3) == "www")
				$links[$key] = "http://".$links[$key];
			$replace = "<a target='_blank' href='".$links[$key]."'>".substr( $links[$key], 0, ($limit - 3) )."...</a>";
		}
		else
			$replace = $links[$key];
		$txt = preg_replace( "/".preg_quote( $code, "/" )."/", $replace, $txt );
	}
	
	return $txt;
	
}//hs_wordwrap

function hs_unwrap($txt,$divider="&#8203;"){
	
	$txt = hs_ereg_replace($divider,"",$txt);
	return $txt;
	
}//hs_unwrap

function load_page($location){

	Header("Location: ".$location);
	exit;

}//load_page
function load_cookie($name,$value,$expire,$cookie_url=""){

	//if(!$cookie_url){
		//$details = parse_url(URL);
		//$cookie_url = $details["host"];
		//if(hs_eregi("www\.",$cookie_url)){
		//	$cookie_url = hs_eregi_replace("^www","",$details["host"]);
		//}//if
	//}//if

	if(!$GLOBALS["gateway"])
		SetCookie($name,$value,$expire);
	else
		$GLOBALS["output"].= "<cookie name=\"".$name."\" value=\"".$value."\" expire=\"".$expire."\" path=\"/\" domain=\"".$cookie_url."\" />";

}//load_cookie
function get_real_ip()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}
function handle_mail_patterns($text,$values){
	
	$patterns = array_keys($values);
	$patterns[] = "site_name";
	$values["site_name"] = $GLOBALS["settings"]["site_name"];
	foreach($patterns as $pat){
		if(strstr($pat, "link") && !strstr($values[$pat],"href")){
			$text = str_replace('href="|'.$pat.'|','href="'.$values[$pat],$text);
			$text = str_replace("href='|".$pat."|","href='".$values[$pat],$text);
			$text = str_replace("|".$pat."|","<a href=\"".$values[$pat]."\">".$values[$pat]."</a>",$text);
		}
		else
			$text = str_replace("|".$pat."|",$values[$pat],$text);
			
	}//foreach

	return $text;

}//handle_mail_patterns
function ground($int1,$int2,$num)
{
	$znum1=0;
	$xnum1=0;
	$znum2=0;
	$xnum2=0;
	$nznum=0;
	$nxnum=0;
	$nnumber=0;
	if(strpos($int1,".")):
		$date=explode(".",$int1);
		$znum1=$date[0];
		if($date[1]==''):
		$date[1]=0;
		endif;
		$xnum1='0.'.$date[1];
	else:
		$znum1=$int1;
		endif;
	if(strpos($int2,".")):
		$date=explode(".",$int2);
		$znum2=$date[0];
		if($date[1]==''):
		$date[1]=0;
	endif;
		$xnum2='0.'.$date[1];
	else:
		$znum2=$int2;
	endif;	
	
	if($znum1>=$znum2):
	$nnum=mt_rand($znum2,$znum1);
	else:
	$nnum=mt_rand($znum1,$znum2);
	endif;
	//整数随机
	$date1=explode(".",$int1);
	$date2=explode(".",$int2);
	if((float)$xnum1>=(float)$xnum2):
		$nxnum=mt_rand($date2[1],$date1[1]);
	else:
		$nxnum=mt_rand($date1[1],$date2[1]);
	endif;
	$nxnum="0.".$nxnum;
	$nnumber=$nnum+$nxnum;
	$nnumber=round($nnumber,$num);
	return $nnumber;
}

function keep($num)
{
//	$str=".00";
//	$newnum="";
//	$price="";
//	if(strpos($num,".")):
//	//find
//	$num1=round($num,2);
//	$newnum=(float)$num1;
//	else:
//	//Did not find
//	$newnum=$num.$str;
//	endif;
//	$price=$newnum;
//	return $price;
        $str=".00";
	$newnum="";
	$price="";
//        echo strpos($num,".");
//        echo "||";
//        echo strlen($num);
	if(strpos($num,".") && ((strpos($num,".")+2)==strlen($num))){
	//find
            $price=$num."0";
        }elseif(strpos($num,"."))
        {
            $num1=round($num,2);
            $newnum=(float)$num1;
            $price=$newnum;
        }else
        {
	//Did not find
            $newnum=$num.$str;
            $price=$newnum;
        }
       return $price;
}

function get_c_name($cid,$commit,$table)
{
	$info = $GLOBALS["DB"]->result("SELECT $commit FROM $table where id='$cid'");
	$c_name=$info[0][$commit];
	return $c_name;
}
?>